#include "SpriteSheet.hpp"

SpriteSheet::SpriteSheet():
    Object2D("", "", 0, 0, 0, 0)
{
}

SpriteSheet::SpriteSheet(QString const& name, QString const& path, const int initialSpriteWidth, const int initialSpriteHeight):
    Object2D(name, path, initialSpriteWidth, initialSpriteHeight, 0, 0)
{
}

void        SpriteSheet::addSprite(QString const& name, QPixmap pixmap)
{
    _cuttedSprites.push_back(std::pair<QString, QPixmap>(name, pixmap));
}

std::list<std::pair<QString, QPixmap> >*    SpriteSheet::getSprites()
{
    return &_cuttedSprites;
}

QPixmap*                                    SpriteSheet::getImageFromName(QString const& name)
{
    std::list<std::pair<QString, QPixmap> >::iterator   spritesBegin = _cuttedSprites.begin();
    std::list<std::pair<QString, QPixmap> >::iterator   spritesEnd = _cuttedSprites.end();

    while (spritesBegin != spritesEnd)
    {
        if ((*spritesBegin).first == name)
        {
            return &((*spritesBegin).second);
        }
        ++spritesBegin;
    }
    return NULL;
}

bool                                    SpriteSheet::alreadyLoaded(std::list<SpriteSheet*>& sheetsDictionary, QString newName)
{
    std::list<SpriteSheet*>::iterator   itBegin = sheetsDictionary.begin();
    std::list<SpriteSheet*>::iterator   itEnd = sheetsDictionary.end();

    while (itBegin != itEnd)
    {
        if ((*itBegin)->getName() == newName)
            return true;
        ++itBegin;
    }
    return false;
}
